import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Index",
    redirect: "/banner",
    component: () => import("../views/IndexPage"),
    children: [
      {
        path: "banner",
        name: "Banner",
        component: () => import("../views/BannerList")
      },
      {
        path: "hotsearch",
        name: "hotsearch",
        component: () => import("../views/HotSearch")
      },
      {
        path: "menulist",
        name: "menulist",
        component: () => import("../views/MenuList")
      },
      {
        path: "goodsClass",
        name: "goodsClass",
        component: () => import("../views/GoodsClass")
      },
      {
        path: "goodsList",
        name: "goodsList",
        component: () => import("../views/GoodsList")
      },
      {
        path: "goodsedit/:type",
        name: "goodsedit",
        component: () => import("../views/GoodsEdit")
      },
      {
        path: "superuserlist",
        name: "superuserlist",
        component: () => import("../views/AdminList")
      },
      {
        path: "userList",
        name: "userList",
        component: () => import("../views/UserList")
      },
      {
        path: "yaowuguomin",
        name: "yaowuguomin",
        component: () => import("../views/YaoWuGuoMin")
      },
      {
        path: "foodguomin",
        name: "foodguomin",
        component: () => import("../views/FoodGuoMin")
      },
      {
        path: "manxingbing",
        name: "manxingbing",
        component: () => import("../views/ManBing")
      },
      {
        path: "familybing",
        name: "familybing",
        component: () => import("../views/FamilyBing")
      },
      {
        path: "selfdone",
        name: "selfdone",
        component: () => import("../views/SelfDone")
      },

      {
        path: "infoclass",
        name: "infoclass",
        component: () => import("../views/InfoClass")
      },

      {
        path: "infolist",
        name: "infolist",
        component: () => import("../views/InfoList")
      },

      {
        path: "infoadd/:type",
        name: "infoadd",
        component: () => import("../views/InfoAdd")
      },

      {
        path: "keshilist",
        name: "keshilist",
        component: () => import("../views/KeshiList")
      },
      

    ]
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/Login")
  }

];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  scrollBehavior:(to, from, savePosition) => {
    return {
      x:0,
      y:0
    }
  },
  routes
});

router.beforeEach((to, from, next) => {
  let token = localStorage.token
  let path = to.path
  console.log(path);
  
  if (!token && path != "/login") {
    next("/login")
  } else {
    next()
  }
})

export default router;
